#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 5005;
const int MIN = -1e4, MAX = 1e4;
const int R = 2e4 + 5;
int n, m;

struct Line {
  int l, r, h, d;
  bool operator<(const Line& b) const {
    if (h != b.h) return h < b.h;
    return d > b.d;  // 先增再减，方便处理重合处
  }
} linesx[N << 1], linesy[N << 1];

struct ScanLine {
  int sum[R << 2], tag[R << 2];
  void pushup(int p, int l, int r) {
    if (tag[p])
      sum[p] = r - l;
    else if (l + 1 < r)
      sum[p] = sum[p << 1] + sum[p << 1 | 1];
    else
      sum[p] = 0;
  }
  void addtag(int d, int p, int l, int r) {
    tag[p] += d;
    pushup(p, l, r);
  }
  void update(int L, int R, int d, int p, int l, int r) {
    if (L <= l && R >= r) {
      addtag(d, p, l, r);
      return;
    }
    int mid = (l + r) >> 1;
    if (L < mid) update(L, R, d, p << 1, l, mid);
    if (R > mid) update(L, R, d, p << 1 | 1, mid, r);
    pushup(p, l, r);
  }
} slx, sly;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) {
    int x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    linesx[i] = Line{x1, x2, y1, 1};
    linesx[i + n] = Line{x1, x2, y2, -1};
    linesy[i] = Line{y1, y2, x1, 1};
    linesy[i + n] = Line{y1, y2, x2, -1};
  }
  sort(linesx + 1, linesx + n * 2 + 1);
  sort(linesy + 1, linesy + n * 2 + 1);
  int ans = 0;
  rep(i, 1, n * 2) {
    int pre = slx.sum[1];
    slx.update(linesx[i].l, linesx[i].r, linesx[i].d, 1, MIN, MAX);
    int now = slx.sum[1];
    ans += abs(now - pre);
  }
  rep(i, 1, n * 2) {
    int pre = sly.sum[1];
    sly.update(linesy[i].l, linesy[i].r, linesy[i].d, 1, MIN, MAX);
    int now = sly.sum[1];
    ans += abs(now - pre);
  }
  cout << ans;
  return 0;
}